///////////////////////////////////////////////////////////
///////////////// Have an itch? Scratch it! ///////////////
///////////////////////// SCRATCH /////////////////////////
/////////////////////  A MUD  Server   ////////////////////
///////////////////// By: Jared Devall ////////////////////
/////////////////////      Thanks:     ////////////////////
/////////////////////  DIKU/Merc/ROM   ////////////////////
///////////////////// Aetas/Deus Gang  ////////////////////
/////////////////////       Beej       ////////////////////
///////////////////////////////////////////////////////////

#include "split.h"
#include <string>

using namespace std;

//////////////
// Get Word //
//////////////
string::const_iterator getword ( const string &src, string &dest, const char delim ) {
	return getword( src.begin(), src.end(), dest, delim );
}

string::const_iterator getword ( string::const_iterator it, string::const_iterator end, string &dest, const char delim ) {
	for ( ; it != end; ++it ) {
		if ( *it == delim ) {
			++it;
			break;
		}
		dest += *it;
	}
	return it;
}

/////////////////
// Split Delim //
/////////////////
vector< string > split( const string &src, char delim ) {
	vector<string> dest;
    string current;
 
	for ( string::const_iterator c = src.begin(); c != src.end(); ++c ) {
		if ( (*c) == delim ) {
			dest.push_back( current );
 		   current = "";
			continue;
 	   } else {
 	   	current.push_back( (*c) );
 	   }
	}
 
    if ( !current.empty() )
    	dest.push_back( current );
 
    return dest;
}

string::const_iterator split( const string &src, string &word1, char delim ) {
	return getword( src, word1, delim );
}
string::const_iterator split( const string &src, string &word1, string &word2, char delim ) {
	return getword( getword( src, word1, delim ), src.end(), word2, delim );
}
string::const_iterator split( const string &src, string &word1, string &word2, string &word3, char delim ) {
    return getword( getword( getword(src, word1, delim ), src.end(), word2, delim ), src.end(), word3, delim );
}
string::const_iterator split( const string &src, string &word1, string &word2, string &word3, string &word4, char delim ) {
    return getword( getword( getword( getword( src, word1, delim ), src.end(), word2, delim ), src.end(), word3, delim ), src.end(), word4, delim );
}

///////////
// Split //
///////////
string::const_iterator split( const string &src, string &word1 ) {
	return getword( src, word1, '\0' );
}
string::const_iterator split( const string &src, string &word1, string &word2 ) {
	return getword( getword( src, word1 ), src.end(), word2, '\0' );
}
string::const_iterator split( const string &src, string &word1, string &word2, string &word3 ) {
	return getword( getword( getword( src, word1 ), src.end(), word2 ), src.end(), word3, '\0' );
}
string::const_iterator split ( const string &src, string &word1, string &word2, string &word3, string &word4 ) {
	return getword( getword( getword( getword( src, word1 ), src.end(), word2 ), src.end(), word3 ), src.end(), word4, '\0' );
}


string quotesSplit( const string &src, string &dest ) {
	string::const_iterator it;
	
	for ( it = src.begin(); it != src.end(); ++it ) {
	}
}
